//
//  HMOriginalView.swift
//  weibo28
//
//  Created by 范英强 on 16/3/25.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMOriginalView: UIView {
    
    var status: HMStatus?{
        didSet{
            // 设置头像
            headImageView.sd_setImageWithURL(NSURL(string: status?.user?.profile_image_url ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
            // 设置昵称
            nameLabel.text = status?.user?.name
            // 会员等级
            mbrankImageView.image = status?.user?.mbrankImage
            // 时间（先这么个默认数据 后续再处理）
            timeLabel.text = "时间"
            // 来自哪里 （先这么个默认数据 后续再处理）
            sourceLabel.text = "来自传智博客微博"
            // 认证
            verifiedImageView.image = status?.user?.verifiedImage
            // 文字内容
            contentLabel.text = status?.text
           
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: -  设置视图
    private func setupUI(){
        backgroundColor = RandomColor()
        // 01 添加控件
        addSubview(headImageView)
        addSubview(nameLabel)
        addSubview(mbrankImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(verifiedImageView)
        addSubview(contentLabel)
        // 02 添加约束
        headImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(HMStatusCellMargin)
            make.leading.equalTo(self).offset(HMStatusCellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView)
            make.leading.equalTo(headImageView.snp_trailing).offset(HMStatusCellMargin)
        }
        
        mbrankImageView.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(nameLabel)
            make.leading.equalTo(nameLabel.snp_trailing).offset(HMStatusCellMargin)
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(headImageView)
            make.leading.equalTo(nameLabel)
        }
        
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(timeLabel)
            make.leading.equalTo(timeLabel.snp_trailing).offset(HMStatusCellMargin)
        }
        
        verifiedImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView.snp_trailing)
            make.centerY.equalTo(headImageView.snp_bottom)
        }
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(HMStatusCellMargin)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contentLabel).offset(HMStatusCellMargin)
        }
        
        
    }
    
    // MARK: - 懒加载控件
    // 头像
    private lazy var headImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    // 昵称
    private lazy var nameLabel:UILabel = {
        let lab = UILabel(textColor: UIColor.darkGrayColor(), font: 14)
        lab.text = "名字"
        return lab
    }()
    // 会员等级
    private lazy var mbrankImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    //时间
    private lazy var timeLabel: UILabel = {
        let lab = UILabel(textColor: themeColor, font: 10)
        return lab
    }()
    //来自哪里
    private lazy var sourceLabel: UILabel = {
        let lab = UILabel(textColor: UIColor.grayColor(), font: 10)
        return lab
    }()
    
    // 认证
    private lazy var verifiedImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vgirl"))
    
    // 文字
    private lazy var contentLabel: UILabel = {
        let lab = UILabel(textColor: UIColor.darkGrayColor(), font: 14, maxWidth: SCREENW - 2 * HMStatusCellMargin)
        return lab
    }()
    

}
